#include "textures.h"

#include <SDL/SDL.h>
#include <SDL/SDL_image.h>

#include <iostream>
using namespace std;

void Texture::Load(string sFileName, GLenum Type)
{
    SDL_Surface *BMP = IMG_Load(sFileName.c_str());

    glGenTextures(1, &uId);
    glBindTexture(Type, uId);

    if(BMP->format->Amask) gluBuild2DMipmaps(Type, 4, BMP->w, BMP->h, GL_RGBA, GL_UNSIGNED_BYTE, BMP->pixels);
    else gluBuild2DMipmaps(Type, 3, BMP->w, BMP->h, GL_BGR, GL_UNSIGNED_BYTE, BMP->pixels);

    glTexParameteri(Type, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(Type, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}

GLuint Texture::GetId()
{
    return uId;
}

void Texture::SetId(GLuint uNewId)
{
    uId = uNewId;
}
